<?php
namespace Utuo\TagLib;

use Think\Template\TagLib;

class Category extends TagLib {
	
	/**
	 * 定义标签列表
	 * @var array
	 */
	protected $tags = array(
		'list' => array('attr' => 'id,category,tag', 'close' => 1), //获取指定分类列表
	);
	
	/**
	 * 子栏目列表
	 * @param array $tags
	 * @param string $content
	 */
	public function _list($tag, $content) {
		$id   = $tag['id'];
		$cate   = $tag['category'];
		$tag = empty($tag['tag'])?"article":"'".$tag['tag']."'";
		if(!$cate) $cate = I('cat', 0, 'intval');
		$tt = <<<'EOT'
		<?php
		$__LIST__ = D('CommonCategory')->realModel({3})->getChildren(null, {0}, $sid);
		foreach($__LIST__ as &$v) {
			$type = $v['type'];
			if($type=='news'){
				$v['url'] =  get_category_url('Index', 'news', $sid, $v['id']);	
			}elseif($type=='url'){
			}elseif($type=='list'){
				if($v['has_child']){
					$v['url'] = get_category_url({3}, 'cate', $sid, $v['id']);		
				}else{
				    $v['url'] = get_category_url({3}, 'list', $sid, $v['id']);	
				}		
			}
		}
		?>
		<volist name="__LIST__" id="{1}">
		{2}
		</volist>				
EOT;
		$parse = \Utuo\String::format($tt, $cate, $id, $content, $tag);
		return $parse;
	}	
}